<?php
namespace Api\Controller;

use Common\Controller\AdminbaseController;

class GuestbookadminController extends AdminbaseController{
	
	protected $guestbook_model;
	
	public function _initialize() {
		parent::_initialize();
		$this->guestbook_model=D("Common/Guestbook");
	}
	
	// 后台留言列表
	public function index(){
		$count=$this->guestbook_model->where(array("status"=>array("neq",0)))->count();
		$page = $this->page($count, 20);
		$guestmsgs=$this->guestbook_model->where(array("status"=>array("neq",0)))->order(array("createtime"=>"DESC"))->limit($page->firstRow . ',' . $page->listRows)->select();
		$this->assign("page", $page->show('Admin'));
		$this->assign("guestmsgs",$guestmsgs);
		$this->display();
	}
//回复内容
	public function reply(){
		$id=I("get.id",0,'intval');
		$guestmsg = $this->guestbook_model->where(array("id"=>$id))->find();
		$this->assign("guestmsg",$guestmsg);
		$this->display();
	}

	public function reply_msg(){
		$id=I("post.msg_id");
		$reply_msg = I("post.reply_msg");
		$replymsg = $this->guestbook_model->where(array("id"=>$id))->save(array("reply_msg"=>$reply_msg));
		if($replymsg !== false){
			$this->success("回复成功");
		}else{
			$this->error("回复失败");
		}
	}
	// 删除留言
	public function check(){
		$id=I("get.id",0,'intval');
		if($_GET['check']){
			$result=$this->guestbook_model->where(array("id"=>$id))->save(array("status"=>1));
			if($result!==false){
				$this->success("审核成功！", U("Guestbookadmin/index"));
			}else{
				$this->error('审核失败！');
			}
		}elseif($_GET['uncheck']){
			$result=$this->guestbook_model->where(array("id"=>$id))->save(array("status"=>2));
			if($result!==false){
				$this->success("取消审核成功！", U("Guestbookadmin/index"));
			}else{
				$this->error('取消审核失败！');
			}
		}
	}

	// 删除留言
	public function delete(){
		$id=I("get.id",0,'intval');
		$result=$this->guestbook_model->where(array("id"=>$id))->save(array("status"=>0));
		if($result!==false){
			$this->success("删除成功！", U("Guestbookadmin/index"));
		}else{
			$this->error('删除失败！');
		}
	}
}